const ws = require("nodejs-websocket");
console.log("开始建立连接...")

const socket = ws.createServer(function(conn){
    conn.on("text", function (str) {
        console.log("message:"+str)
        let msg = "你好，这里是是日前端~"
        // let msg = 'websocket处于正常状态'
        setInterval(() => {
            conn.sendText(msg);
        }, 3000)
    })
    conn.on("close", function (code, reason) {
        console.log("关闭连接")
    });
    conn.on("error", function (code, reason) {
        console.log("异常关闭", code, reason)
    });
}).listen(8666)
console.log("WebSocket建立完毕")

module.exports = socket